﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace yncTech.Common
{
    /// <summary>
    /// ApplicationState
    /// </summary>
    public class ApplicationState
    {
        #region Members
        private static string absoluteUri;
        #endregion

        #region 构造函数
        static ApplicationState()
        {
            //在第一次时初始化应用程序的基目录的绝对URI

            absoluteUri = VirtualPathUtility.AppendTrailingSlash(HttpContext.Current.Request.ApplicationPath);
        }
        #endregion

        #region Attributes
        /// <summary>
        /// ApplicationPath.
        /// </summary>
        public static string ApplicationPath
        {
            get
            {
                return AppDomain.CurrentDomain.BaseDirectory;
            }
        }

        /// <summary>
        /// 取得应用程序的绝对URI.
        /// </summary>
        /// <value>The absolute URI.</value>
        /// <remarks>
        /// 对于Web程序返回形如：/MyWeb/;
        /// 对于Win程序返回形如：file:///C:/MyWin/
        /// </remarks>
        public static string AbsoluteUri
        {
            get
            {
                return absoluteUri;
            }
        }

        /// <summary>
        /// 完整虚拟路径
        /// </summary>
        /// <remarks>
        /// 形如:http://localhost:8080/MyWeb
        /// </remarks>
        public static string AbsoluteFullUri
        {
            get
            {
                string absoluteUri = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
                string tempPath = HttpContext.Current.Request.ApplicationPath;
                absoluteUri = absoluteUri + tempPath;
                return VirtualPathUtility.AppendTrailingSlash(absoluteUri);
            }
        }
        #endregion
    }
}
